<template>
  <div class="ek-drawer">
    <el-drawer v-model="visiable" :title="ekTitle" size="60%" ref="ekDrawer">
      <div class="ek-drawer-body">
        <slot></slot>
      </div>
      <div class="ek-drawer-footer" v-if="!hideBtn">
        <el-button type="primary" @click.stop="handleClose">取消</el-button>
        <el-button type="primary" @click.stop="handleSubmit">确定</el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script setup>
import {
  defineComponent,
  onMounted,
  getCurrentInstance,
  ref,
  reactive,
  computed,
  defineEmits
} from "vue";

import { useStore } from "vuex";
import { useRouter } from "vue-router";

const props = defineProps({
  // 显示/隐藏
  modelValue: {
    type: Boolean,
    default: false,
  },
  // 标题
  title: {
    type: String,
    default: "",
  },
  // 是否隐藏操作按钮
  hideBtn: {
    type: Boolean,
    default: false,
  },
});

const {
  appContext: {
    config: { globalProperties },
  },
} = getCurrentInstance();

const { $storage, $http } = globalProperties;
const store = useStore();
const router = useRouter();

const emit = defineEmits(["update:modelValue", "submit"]);
const visiable = computed({
  get() {
    return props.modelValue;
  },
  set(value) {
    emit("update:modelValue", value);
  },
});
const ekTitle = computed({
  get() {
    return props.title;
  },
});

const ekDrawer = ref(null);
function handleClose()  {
  ekDrawer.value.handleClose();
};

function handleSubmit() {
  emit("submit", () => {
    handleClose();
  });
};
</script>

<style scoped lang="scss">
.ek-drawer {
  position: relative;
  :deep(.el-drawer__header) {
    text-align: left;
    border-bottom: 1px solid #e2e2e2;
    padding-bottom: 15px;
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 0px;
  }
  :deep(.el-drawer__body) {
    overflow: hidden;
  }
  .ek-drawer-footer {
    width: 100%;
    position: absolute;
    bottom: 0;
    right: 0;
    padding: 12px 32px;
    border-top: 1px solid #e2e2e2;
    text-align: right;
  }
  .ek-drawer-body {
    width: 100%;
    height: calc(100% - 50px);
  }
}
</style>
